 /*///////////////////////////////////////////////////////////////////////////////
-- Author:      liuhx
-- Created:     Thu Nov 15 17:19:04 CST 2018
-- Description:	    
-- If you have any question,please email to liuhx@gentlesoft.com.cn 
////////////////////////////////////////////////////////////////////////////////*/
package com.ctsi.product.service;

 import com.ctsi.commons.util.UtilValidate;
 import com.ctsi.commons.util.id.UUIDGenerator;
 import com.ctsi.commons.util.response.Page;
 import com.ctsi.framework.mybatis.support.MybatisGenericDao;
 import com.ctsi.product.entity.PinglunNumber;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;

 import java.util.List;
 import java.util.Map;


/**
 * PinglunNumber Service 类
 * @author   liuhx
 * @description  PinglunNumber
 * @created	 Thu Nov 15 17:19:04 CST 2018
 */

@Service
public class PinglunNumberService {
	private static final Logger logger=LoggerFactory.getLogger(PinglunNumberService.class);
	@Autowired
	private MybatisGenericDao dao;


	/**
	 * 根据productid查询产品对应的评论数量
	 */
	public Object selectPinLunNumByProductId(String productId){
		logger.debug("selectPinLunNumByProductId {}",productId);
		return 	dao.queryForObject(PinglunNumber.class.getName() + ".selectPinLunNumByProductId", productId);
	}

	/**
	 * 每次评论都会生成一条数据记录
	 */
	public int insertPinglunNumber(PinglunNumber pinglunNumber){
		if(UtilValidate.isEmpty(pinglunNumber.getId()))
			pinglunNumber.setId(UUIDGenerator.getId());
		logger.debug("insert {}",pinglunNumber);
	return 	dao.insert(pinglunNumber);
	}

/**
 * 根据产品id查询评论列表
 */
public Page<PinglunNumber> queryPinLunByProductId(Map<String,Object> param , int start , int pageSize){
	logger.debug("queryPinLunByProductId {}",param);
	if(pageSize<0||pageSize>2000)
		pageSize=Page.DEFAULT_PAGE_SIZE;
	if(start!=-1)
		return dao.queryPage(PinglunNumber.class.getName()+".queryPinLunByProductId", param, start, pageSize);
	else{
		throw new RuntimeException("参数不正确 !!");
	}
}

	/**
	 * 动态更新
	 */	
	public int updatePinglunNumberByPKSelective(PinglunNumber pinglunNumber){
		logger.debug("updateByPrimaryKeySelective {}",pinglunNumber);
		return dao.update(PinglunNumber.class.getName()+".updateByPrimaryKeySelective", pinglunNumber);
	}
	/**
	 * 更新
	 */
	public int updatePinglunNumber(PinglunNumber pinglunNumber){
		logger.debug("update {}",pinglunNumber);
		return dao.update(pinglunNumber);
	}
	
	
	public PinglunNumber editPinglunNumberById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("editById {}",id);
		return (PinglunNumber)dao.queryForObject(PinglunNumber.class.getName()+".edit", id);
	}
	/**
	 * 根据ID查找 PinglunNumber对象
	 */
	public PinglunNumber findPinglunNumberById(String id){
		if(UtilValidate.isEmpty(id))
			return null;
		logger.debug("findById {}",id);
		return dao.get(PinglunNumber.class, id);
	}
	/**
	 * 删除PinglunNumber对象
	 */
	public int removePinglunNumber(String id){	
		if(UtilValidate.isNotEmpty(id))
			return dao.delete(PinglunNumber.class.getName()+".delete", id);
			//return dao.remove(id);
		return 0;
	}
	
	/**
	 * 详细页查询
	 */
	public PinglunNumber findByDetail(String id){
		return (PinglunNumber)dao.queryForObject(PinglunNumber.class.getName()+".findByDetail",id);
	}
	/** 
	 * 多条件查询结果 
	 */
	public Page<PinglunNumber> findByMulitCondition(Map<String,Object> param , int start , int pageSize){
		logger.debug("findByMulitCondition {}",param);
		if(pageSize<0||pageSize>2000)
			pageSize=Page.DEFAULT_PAGE_SIZE;
		if(start!=-1)
			return dao.queryPage(PinglunNumber.class.getName()+".selectMulitCondition", param, start, pageSize);
		else{
			throw new RuntimeException("参数不正确 !!");
		}
	}
	/** 
	 * 多条件查询结果不分页
	 */
	public List<PinglunNumber> find(Map<String,Object> map){
		logger.debug("find {}",map);
		return (List<PinglunNumber>)dao.queryForList(PinglunNumber.class.getName()+".selectByMap",map);
	}
	
}
